﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Collections;
using System.Xml.Linq;

public partial class jQueryPaging : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]
    public static IEnumerable GetFeeds(int PageSize, int PageNumber)
    {
        string strFeedUrl = "http://news.baidu.com/n?cmd=1&class=civilnews&tn=rss";
        //"http://www.cnblogs.com/rss";

        //System.Configuration.ConfigurationManager.AppSettings["FeedUrl"];

        XDocument feedXML = XDocument.Load(strFeedUrl);

        var feeds = from feed in feedXML.Descendants("item")
                    select new
                    {
                        Date = DateTime.Parse(feed.Element("pubDate").Value).ToShortDateString(),
                        Title = feed.Element("title").Value,
                        Link = feed.Element("link").Value,
                        Description = feed.Element("description").Value,
                    };

        //paging... (LINQ)
        return feeds.Skip((PageNumber - 1) * PageSize).Take(PageSize);
    }

    [WebMethod]
    public static int GetFeedsCount()
    {
        string strFeedUrl = "http://news.baidu.com/n?cmd=1&class=civilnews&tn=rss";

        XDocument feedXML = XDocument.Load(strFeedUrl);

        return feedXML.Descendants("item").Count();
    }

}